import Vue from "vue";
import App from "./App.vue";
import Header from "@/components/Header/index.vue";
import router from "./router";
import store from "@/store";
import ElementUI from 'element-ui';

/* 加载mint-ui框架 */
import Mint from "mint-ui";
import "mint-ui/lib/style.css";

import "element-ui/lib/theme-chalk/index.css";
import "@/styles/index.scss"; // 加载全局 css
import "./permission.js"; //加载路由跳转控制

import { Switch } from "element-ui";

require("promise.prototype.finally").shim(); // axios不支持finally的解决办法
Vue.use(ElementUI);
Vue.use(Mint);
Vue.config.productionTip = false;

/* 全局注册header组件 */
Vue.component("AppHeader", Header);
Vue.component("AppSwitch", Switch);

/* 全局指令 */
Vue.directive("hint-emoji", {
  bind: function(el) {
    const inputElem = el.querySelector("input") || el.querySelector("textarea");
    inputElem.oninput = function() {
      const reg = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g;
      if (reg.test(inputElem.value)) {
        Mint.Toast({
          message: "请不要输入表情字符!",
          position: "middle",
          duration: 1200
        });
      }
    };
  }
});

/* 提取本地缓存信息 */
const app = JSON.parse(localStorage.getItem("app"));
if (app && Object.prototype.toString.call(app) === "[object Object]") {
  store.dispatch("user/login", app);
}

const vm = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

//FIXME: 测试用
/* eslint-disable */
console.log(process.env)
console.log('NODE_ENV:', process.env.NODE_ENV) //eslint-disable-line
// eslint-disable-next-line
console.log(process.env.VUE_APP_TITLE)
console.log(process.env.VUE_APP_VERSION)
/* eslint-enable */
console.log("VUE_APP_APIENV：", process.env.VUE_APP_APIENV);

export default vm;
